/**
 * 
 */
package orz.mikeneck.event.atnd;

import java.util.HashMap;

import orz.mikeneck.event.Event;
import orz.mikeneck.event.Query;
import orz.mikeneck.event.SearchType;

/**
 * @author mike_neck
 *
 */
public class Atnd implements Event {

	/**
	 * Map for Query Instance.
	 */
	private HashMap<String, Query> queryMap;

	/**
	 * 
	 *
	 * @author mike_neck
	 * @since  2011/03/21
	 * @version 0.1 
	 */
	public Atnd(){
		this.queryMap = new HashMap<String, Query>();
	}

	/**
	 * @see orz.mikeneck.event.Event#getQuery(SearchType)
	 */
    @Override
	public Query getQuery(SearchType type) {
    	Query q = null;
    	
    	@SuppressWarnings("unchecked")
        Class<? extends Query> klazz = (Class<? extends Query>) type.getClass();

    	if(queryMap.containsKey(klazz.getName())){
    		q = queryMap.get(klazz.getName());
    	}else{
            try {
    	        q = type.getQueryClass().newInstance();
    	        queryMap.put(klazz.getName(), q);
            } catch (InstantiationException e) {
    	        e.printStackTrace();
            } catch (IllegalAccessException e) {
    	        e.printStackTrace();
            }
    	}
		return q;
	}

	/**
	 * 
	 * @see orz.mikeneck.event.Event#getUrl(orz.mikeneck.event.SearchType)
	 */
	@Override
	public String getUrl(SearchType type) {
		return type.getRequestUrl();
	}

}
